package org.iblink.gui.swing.dnd.transferable;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.List;

import org.iblink.core.domain.model.Asset;
import org.iblink.gui.swing.dnd.flavor.AssetListFlavor;

public class TransferableAssetList implements Transferable {
  
  private List<Asset> assets;
  
  public TransferableAssetList(List<Asset> assets) {
    this.assets = assets;
  }

  @Override
  public Object getTransferData(DataFlavor flavor)
      throws UnsupportedFlavorException, IOException {
    if (!isDataFlavorSupported(flavor)) {
      throw new UnsupportedFlavorException(flavor);
    }
    return assets;

  }

  @Override
  public DataFlavor[] getTransferDataFlavors() {
    DataFlavor[] flavors = new DataFlavor[1];
    try {
      flavors[0] = new AssetListFlavor();
    } catch (ClassNotFoundException e) {
      return null;
    }
    return flavors;
  }

  @Override
  public boolean isDataFlavorSupported(DataFlavor flavor) {
    return flavor != null && flavor instanceof AssetListFlavor;
  }
}
